package com.aliyun.messagemgt.controller;

import com.aliyun.messagemgt.application.service.MessageTemplateService;
import com.aliyun.messagemgt.application.service.OperateLogService;
import com.aliyun.messagemgt.dto.MessageTemplate;
import com.aliyun.messagemgt.dto.MessageTemplateParam;
import com.aliyun.messagemgt.dto.query.MessageTemplateQuery;
import com.aliyun.messagemgt.web.controller.MessageTemplateController;
import com.github.pagehelper.PageInfo;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.test.annotation.Rollback;

import java.util.ArrayList;
import java.util.List;

/**
 * @author wenyaxin
 * @date 2020/12/2
 */
@RunWith(MockitoJUnitRunner.class)
public class MessageTemplateControllerTest {

    @InjectMocks
    private MessageTemplateController messageTemplateController;

    @Mock
    private MessageTemplateService messageTemplateService;

    @Mock
    private OperateLogService operateLogService;

    @Test
    @Rollback()
    public void templateOffLineTest(){
        MessageTemplate messageTemplate = new MessageTemplate();
        messageTemplate.setTemplateName("1");
        Mockito.when(messageTemplateService.templateDetail(Mockito.any())).thenReturn(messageTemplate);
        Mockito.when(messageTemplateService.templateModify(Mockito.any())).thenReturn(1);
        Mockito.when(operateLogService.insertOperateLog(Mockito.any())).thenReturn(1);
        messageTemplateController.templateOffLine(createMessageTemplateAdd());
    }

    @Test
    @Rollback()
    public void templateDeleteTest(){
        MessageTemplate messageTemplate = new MessageTemplate();
        messageTemplate.setTemplateName("1");
        Mockito.when(messageTemplateService.templateDetail(Mockito.any())).thenReturn(messageTemplate);
        Mockito.when(messageTemplateService.templateDelete(Mockito.any())).thenReturn(1);
        Mockito.when(operateLogService.insertOperateLog(Mockito.any())).thenReturn(1);
        messageTemplateController.templateDelete(createTemplateQuery());
    }

    @Test
    @Rollback()
    public void detailTest(){
        Mockito.when(messageTemplateService.templateDetail(Mockito.any())).thenReturn(new MessageTemplate());
        messageTemplateController.detail(createTemplateQuery());
    }

    @Test
    @Rollback()
    public void msgTemplateListTest(){
        Mockito.when(messageTemplateService.queryList(Mockito.any())).thenReturn(new PageInfo());
        Object a = messageTemplateController.msgTemplateList(createTemplateQuery());
    }

    private MessageTemplate createMessageTemplateAdd(){
        MessageTemplate messageTemplateAdd = new MessageTemplate();
        messageTemplateAdd.setTemplateId(1L);
        messageTemplateAdd.setUserId("1");
        messageTemplateAdd.setUserName("1");
        messageTemplateAdd.setDepartment("1");
        messageTemplateAdd.setDepartmentName("1");
        return messageTemplateAdd;
    }

    private MessageTemplateQuery createTemplateQuery(){
        MessageTemplateQuery templateQuery = new MessageTemplateQuery();
//        templateQuery.setTemplateId(1L);
//        templateQuery.setUserId("1");
//        templateQuery.setUserName("1");
//        templateQuery.setDepartment("1");
//        templateQuery.setDepartmentName("1");
//        templateQuery.setId(1L);
        List<String> list = new ArrayList<>();
        list.add("MOM");
        templateQuery.setTenantCodeList(list);
        templateQuery.setPageNum(1);
        templateQuery.setPageSize(10);
        return templateQuery;
    }
}
